package org.xa3apm.vote.hibernate.entities;

import java.io.Serializable;
import java.lang.Long;
import java.lang.String;
import java.util.ArrayList;
import java.util.Collection;

import javax.persistence.*;

/**
 * Entity implementation class for Entity: Party
 * 
 */
@Entity
@Table(name = "tParty")
@NamedQueries({
		@NamedQuery(name = "Party.getById", query = "SELECT P FROM Party P where P.id = :id"),
		@NamedQuery(name = "Party.getAll", query = "SELECT P FROM Party P") })
public class Party implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue
	@Column(name = "id", nullable = false, unique = true, updatable = false)
	private Long id;
	@Column(name = "partyName")
	private String name;
	@OneToMany(mappedBy = "party", orphanRemoval = true, cascade = CascadeType.ALL)
	private Collection<Candidate> candidate;

	public Party() {
		super();
	}

	public Party(String name, Collection<Candidate> candidate) {
		super();
		this.name = name;
		this.candidate = candidate;
	}

	public Long getId() {
		return this.id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Collection<Candidate> getCandidate() {
		if (this.candidate == null) {
			this.candidate = new ArrayList<Candidate>();
		}
		return candidate;
	}

	public void setCandidate(Collection<Candidate> candidate) {
		this.candidate = candidate;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((candidate == null) ? 0 : candidate.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof Party))
			return false;
		Party other = (Party) obj;
		if (candidate == null) {
			if (other.candidate != null)
				return false;
		} else if (!candidate.equals(other.candidate))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "Party [id=" + id + ", name=" + name + "]";
	}

}
